#include "goodsoutput.h"
#include "ui_goodsoutput.h"

GoodOutput::GoodOutput(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::GoodOutput)
{
    ui->setupUi(this);
    setWindowFlags(windowFlags()&~Qt::WindowMaximizeButtonHint);
    setFixedSize(this->width(),this->height());
     //初始化combo box
     InitComboBoxFunc();
}

GoodOutput::~GoodOutput()
{
    delete ui;
}


void GoodOutput::on_pushButton_out_clicked()
{
    if(ui->lineEdit->text().isEmpty())
        {
            QMessageBox::information(this,"error","请填写数量");
            return;
        }


        QString comboText = ui->comboBox->currentText();
        comboText.remove(QChar('\n')); // 去除换行符，可按需添加其他特殊字符过滤
        int id = comboText.toInt();

        QString lineText = ui->lineEdit->text();
        lineText.remove(QChar('\n'));
        int addamout = lineText.toInt();



        QSqlQuery query;
        QString sql = "update stockdatatable set stockAmout=stockAmout-? where stockId=?";
        query.prepare(sql);
        query.addBindValue(addamout);
        query.addBindValue(id);

        if (!query.exec())
        {
            QMessageBox::information(this,"tip","sql失败"+query.lastError().text());
            return;
        }

        ui->lineEdit->clear();
        QMessageBox::information(this,"tip","出库成功");
        emit deliverSucceeded();
}

void GoodOutput::on_pushButton_exit_clicked()
{
    close();
}
void GoodOutput::InitComboBoxFunc()   //初始化下拉框
{

    int i=0;
    QString strid;
    QSqlQuery query;
    QString str="select *from stockdatatable";
    query.exec(str);
    while(query.next())
    {
        strid=query.value(0).toString();
        ui->comboBox->insertItem(i,strid);
        i++;
    }

}






//
